package com.hualan.sfzy.controller.counselor;

import com.hualan.sfzy.entity.counselor.CounselorOrder;
import com.hualan.sfzy.service.counselor.CounselorOrderService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CounselorOrderController {
    @Autowired
    private CounselorOrderService counselorOrderService;

    @PostMapping("/counselorOrder")
    public Result add(@RequestBody CounselorOrder counselorOrder) {
        int num = counselorOrderService.add(counselorOrder);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/counselorOrder/{id}")
    public Result remove(@PathVariable Integer id){
        int num = counselorOrderService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/counselorOrder")
    public Result removeBatch(Integer[] ids){
        int num = counselorOrderService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    @PutMapping("/counselorOrder")
    public Result update(@RequestBody CounselorOrder counselorOrder){
        int num = counselorOrderService.edit(counselorOrder);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/counselorOrder")
    public Result find(){
        List<CounselorOrder> list = counselorOrderService.find();
        return Result.success(list);
    }

    @GetMapping("/counselorOrder/{id}")
    public Result findById(@PathVariable Integer id){
        CounselorOrder num = counselorOrderService.findById(id);
        return Result.success(num);
    }

    @GetMapping("/counselorOrder/page")
    public Result findByPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                    CounselorOrder counselorOrder){
        Map<String, Object> map = counselorOrderService.findByPage(pageNum, pageSize, counselorOrder);
        return Result.success(map);
    }
}
